import { createLocalVue, shallowMount, Wrapper } from '@vue/test-utils';
import axios from 'axios';
import * as config from '@/shared/config/config';
import ResetPasswordInit from '@/account/reset-password/init/reset-password-init.vue';
import ResetPasswordInitClass from '@/account/reset-password/init/reset-password-init.component';

const localVue = createLocalVue();
const mockedAxios: any = axios;

config.initVueApp(localVue);
<%_ if (enableTranslation) { _%>
const i18n = config.initI18N(localVue);
<%_ } _%>

jest.mock('axios', () => ({
    get: jest.fn(),
    post: jest.fn()
}));

describe('Reset Component Init', () => {
    let wrapper: Wrapper<ResetPasswordInitClass>;
    let resetPasswordInit: ResetPasswordInitClass;

    beforeEach(() => {
        mockedAxios.post.mockReset();
        wrapper = shallowMount<ResetPasswordInitClass>(ResetPasswordInit, {
            <%_ if (enableTranslation) { _%>
            i18n,
            <%_ } _%>
            localVue,
        });
        resetPasswordInit = wrapper.vm;
    });

    it('should reset request be a success', async () => {
        // Given
        mockedAxios.post.mockReturnValue(Promise.resolve());

        // When
        await resetPasswordInit.requestReset();

        // Then
        expect(resetPasswordInit.success).toBeTruthy();
    });

    it('should reset request fail as an error', async () => {
        // Given
        mockedAxios.post.mockReturnValue(Promise.reject({
            response: {
                status: null,
                data: {
                    type: null
                }
            }
        }));

        // When
        resetPasswordInit.requestReset();
        await resetPasswordInit.$nextTick();

        // Then
        expect(resetPasswordInit.success).toBeNull();
        expect(resetPasswordInit.error).toEqual('ERROR');
    });
});
